#include "MenuDlg.h"
#include "resource.h"
#include "WithdrawMoneyDlg.h"
#include "ViewBalanceDlg.h"
#include "ValidateCardDlg.h"
#include "ChangePINDlg.h"
#include "common.h"

LRESULT CALLBACK MenuDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{	
	MenuDlg *Obj;
	if (message==WM_INITDIALOG)
	{	
		Obj=(MenuDlg*)lParam;
		SetWindowLong(hWnd,GWL_USERDATA,(LONG)Obj);
	}
	Obj=(MenuDlg*)GetWindowLong(hWnd,GWL_USERDATA);
	if (Obj)
		return Obj->DialogProc(hWnd, message, wParam, lParam);
	return 0;
}

MenuDlg::MenuDlg(HINSTANCE hInstance, HWND hParent)
{
	DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG_MENU), hParent, (DLGPROC)MenuDlgProc, (LPARAM)this);
}

MenuDlg::~MenuDlg(void)
{
	EndDialog(m_hDlg,0);
}

LRESULT MenuDlg::DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
	case WM_INITDIALOG:
		{	
			m_hDlg = hWnd;			
			return FALSE;
		}		
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{	
		case IDC_BUTTON_WITHDRAW_MONEY:
			{
				EndDialog(hWnd, 0);
				WithdrawMoneyDlg withdrawMoneyDlg(hGlobalInst, m_hDlg);
				return TRUE;
			}
        case IDC_BUTTON_VIEW_BALANCE:
            {
				EndDialog(hWnd, 0);
                ViewBalanceDlg viewBalanceDlg(hGlobalInst, m_hDlg);
                return TRUE;
            }
        case IDC_BUTTON_CHANGE_PIN:
            {
                EndDialog(hWnd, 0);
                CChangePINDlg objChangePINDlg(hGlobalInst, m_hDlg);
                return TRUE;
            }
		case IDCANCEL:
			EndDialog(hWnd, 0);
			CValidateCardDlg objValidateCardDlg(hGlobalInst, NULL);
			return TRUE;
		}
		break;
	default:
		return FALSE;
	}
	return TRUE;
}
